// 在setup中使用mapState的hooks
import { mapState, createNamespacedHelpers } from 'vuex'
import { useMapper } from './useMapper'

// 传入一个模块名
export function useState(moduleName, mapper) {
  let mapperFn = mapState
  // 判断传入的模块名是否是String类型，且长度不为0
  if (typeof moduleName === 'string' && moduleName.length > 0) {
    mapperFn = createNamespacedHelpers(moduleName).mapState
  } else {
    mapper = moduleName
  }
  return useMapper(mapper, mapperFn)
}
